package minov.parser;

/**
 * This class is for arguments that have integers as their parameters.
 *
 */
public class IntegerArgument extends MultipleValueArgument<Integer> {

   /**
    * Constructs argument that parses integer values.<br>
    * Example:
    * 
    * <pre>
    * intArgument = new IntegerArgument(&quot;t&quot;, &quot;timetolive&quot;, 0, 100)
    * </pre>
    * 
    * @param [in] shortName
    *           argument shortcut
    * @param [in] fullName
    *           full name of argument
    * @param [in] minValue
    *           lowest possible value
    * @param [in] maxValue
    *           highest possible value
    * @param [in] defaultValues
    *           default value/values, if no argument was parsed
    */
   public IntegerArgument(String shortName, String fullName, Integer minValue,
         Integer MaxValue, Integer... defaultValues) {
      super(shortName, fullName, defaultValues);
      this._minValue = minValue;
      this._maxValue = MaxValue;
   }

   private Integer _minValue = Integer.MIN_VALUE;
   
   private Integer _maxValue = Integer.MAX_VALUE;

   /**
    * Function for processing one argument. Called by the parser.
    * @param [in] text value to be processed
    * @return processed value
    */
   @Override
   public Integer parseOneArgument(String text) throws Exception {
      return Integer.valueOf(text);
   }

   private static final String BAD_NUMBER_FORMAT_STRING =
         "Argument %s is not within specified boundaries.";

   /**
    * Function for validating one argument value.
    * @param [in] value value to be validated
    * @return ValidationResult object with the result
    */
   @Override
   public ValidationResult validateValue(Integer value) {
      if ((value > _maxValue) || (value < _minValue)) {
         return ValidationResult.createInvalidResponse(String.format(
               BAD_NUMBER_FORMAT_STRING, getDefaultName()));
      }
      return ValidationResult.createValidResponse();
   }

   @Override
   Integer[] getGenericArray() {
      return new Integer[0];
   }
}
